/******************************************************************************\
    Window.hpp contains a class of windows window.
    Copyright (C) 2008  Victor Vinogradov (fly3333@gmail.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
\******************************************************************************/

#pragma once

#include <windows.h>

class cWindow 
{
protected:
	HWND Handle;

	bool Create( DWORD ex_style, LPCTSTR class_name, LPCTSTR window_name, DWORD style, int x, int y, int width, int height, HWND parent, HMENU menu, HINSTANCE instance, LPVOID parameter )
	{
		Handle = CreateWindowEx( ex_style, class_name, window_name, style, x, y, width, height, parent, menu, instance, parameter );
		return Handle != NULL;
	}
public:
	cWindow()
		: Handle( NULL )
	{
	}
	bool GetFromDialog( HWND dialog, int item_id )
	{
		Handle = GetDlgItem( dialog, item_id );
		return Handle != NULL;
	}
	operator HWND() const
	{
		return Handle;
	}
	bool Move( int x, int y, int width, int height, bool repaint )
	{
		return ::MoveWindow( Handle, x, y, width, height, ( BOOL )repaint ) != FALSE;
	}
	bool GetClientRect( LPRECT rect )
	{
		return ::GetClientRect( Handle, rect ) != FALSE;
	}
	LONG SetLong( int offset, LONG value )
	{
		return ::SetWindowLong( Handle, offset, value );
	}
	LONG GetLong( int offset )
	{
		return ::GetWindowLong( Handle, offset );
	}
	int GetText( LPTSTR text, int max_length )
	{
		return ::GetWindowText( Handle, text, max_length );
	}
	bool SetText( LPCTSTR text )
	{
		return ::SetWindowText( Handle, text ) != FALSE;
	}
	bool Close()
	{
		return ::CloseWindow( Handle ) != FALSE;
	}
	bool Destroy()
	{
		return ::DestroyWindow( Handle ) != FALSE;
	}
	UINT_PTR SetTimer( UINT_PTR timer_id, UINT timeout, TIMERPROC timer_func )
	{
		return ::SetTimer( Handle, timer_id, timeout, timer_func );
	}
	LRESULT SendMessage( UINT message, WPARAM wParam, LPARAM lParam )
	{
		return ::SendMessage( Handle, message, wParam, lParam );
	}
	HWND SetFocus()
	{
		return ::SetFocus( Handle );
	}
	bool GetInfo( PWINDOWINFO window_info )
	{
		return ::GetWindowInfo( Handle, window_info ) != FALSE;
	}
	bool SetPos( HWND window_insert_after, int left, int top, int width, int height, UINT flags )
	{
		return ::SetWindowPos( Handle, window_insert_after, left, top, width, height, flags ) != FALSE;
	}
};
